// var i;
// var AL_GAME_HUA_i18nLabel = require("./AL_GAME_HUA_i18nLabel");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_LevelConfig = require("./AL_GAME_HUA_LevelConfig");
// var AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
// var h = cc._decorator;
// var _ = h.ccclass;
// var P = h.property;
// var g =
//     (h.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.tips = null;
//             t.toggle_pop = null;
//             t.button_label = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.start = function () {
//             AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_shifou_jiesuo()
//                 ? ((this.toggle_pop.node.active = !0),
//                   (this.tips.string = "挑战奖励提示"),
//                   (this.button_label.string = "开始"),
//                   (this.toggle_pop.isChecked = !AL_GAME_HUA_GameData.GameData.getInstance().huoqu_jinri_tiaozhan_pop()))
//                 : ((this.tips.params = [
//                       AL_GAME_HUA_GameConst.GameConst.getInstance().challenge_unlock_level.toString()
//                   ]),
//                   (this.tips.string = "通过x关解锁"),
//                   (this.toggle_pop.node.active = !1),
//                   (this.button_label.string = "确定"));
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showAll: !0
//             });
//         };
//         t.prototype.onEnable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !0
//             });
//         };
//         t.prototype.onDisable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !1
//             });
//         };
//         t.prototype.handle_button_callback = function (e, t) {
//             switch (t) {
//                 case "close":
//                     this.close();
//                     break;
//                 case "start":
//                     AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_shifou_jiesuo()
//                         ? AL_GAME_HUA_Instance.Instance.jiancha_tili_shifou_zugou(function () {
//                               AL_GAME_HUA_Instance.Instance.LevelType = AL_GAME_HUA_Define.Define.LevelType.CHALLENGE;
//                               AL_GAME_HUA_Instance.Instance.ChallengeLevel = 1;
//                               AL_GAME_HUA_Instance.Instance.qianwang_youxi();
//                           })
//                         : this.close();
//                     break;
//                 case "toggle_pop":
//                     var n = this.toggle_pop.isChecked;
//                     AL_GAME_HUA_GameData.GameData.getInstance().shezhi_jinri_tiaozhan_pop(!n);
//             }
//         };
//         __decorate([P(AL_GAME_HUA_i18nLabel.i18nLabel)], t.prototype, "tips", void 0);
//         __decorate([P(cc.Toggle)], t.prototype, "toggle_pop", void 0);
//         __decorate([P(AL_GAME_HUA_i18nLabel.i18nLabel)], t.prototype, "button_label", void 0);
//         return __decorate([_], t);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = g;


// 引入模块
const i18nLabel = require("./AL_GAME_HUA_i18nLabel");
const Instance = require("./AL_GAME_HUA_Instance");
const Define = require("./AL_GAME_HUA_Define");
const PopupSelf = require("./AL_GAME_HUA_PopupSelf");
const GameConst = require("./AL_GAME_HUA_GameConst");
const LevelConfig = require("./AL_GAME_HUA_LevelConfig");
const GameData = require("./AL_GAME_HUA_GameData");

// 使用 Cocos Creator 的装饰器
const { ccclass, property } = cc._decorator;

/**
 * 游戏弹出窗口类
 */
@ccclass
class GamePopup extends PopupSelf.default {
    @property(i18nLabel.i18nLabel)
    tips = null;

    @property(cc.Toggle)
    toggle_pop = null;

    @property(i18nLabel.i18nLabel)
    button_label = null;

    start() {
        const isChallengeUnlocked = LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_shifou_jiesuo();
        const challengeUnlockLevel = GameConst.GameConst.getInstance().challenge_unlock_level.toString();

        if (isChallengeUnlocked) {
            this.toggle_pop.node.active = true;
            this.tips.string = "挑战奖励提示";
            this.button_label.string = "开始";
            this.toggle_pop.isChecked = !GameData.GameData.getInstance().huoqu_jinri_tiaozhan_pop();
        } else {
            this.tips.params = [challengeUnlockLevel];
            this.tips.string = "通过x关解锁";
            this.toggle_pop.node.active = false;
            this.button_label.string = "确定";
        }

        Instance.Instance.xianshi_dingbu_tiao({
            target: this.node,
            showAll: true
        });
    }

    onEnable() {
        AL_APP_SDK_MANAGER.emit(Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: true
        });
    }

    onDisable() {
        AL_APP_SDK_MANAGER.emit(Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: false
        });
    }

    handle_button_callback(event, action) {
        switch (action) {
            case "close":
                this.close();
                break;
            case "start":
                if (LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_shifou_jiesuo()) {
                    Instance.Instance.jiancha_tili_shifou_zugou(() => {
                        Instance.Instance.LevelType = Define.Define.LevelType.CHALLENGE;
                        Instance.Instance.ChallengeLevel = 1;
                        Instance.Instance.qianwang_youxi();
                    });
                } else {
                    this.close();
                }
                break;
            case "toggle_pop":
                const isChecked = this.toggle_pop.isChecked;
                GameData.GameData.getInstance().shezhi_jinri_tiaozhan_pop(!isChecked);
                break;
        }
    }
}

exports.default = GamePopup;